/* The file is saved in UTF-8 codepage.
 * Check: «Stereotype», Section mark-§, Copyright-©, Alpha-α, Beta-β, Smile-☺
 */
package cz.pecinovsky.english.lootp.utility;



////////////////////////////////////////////////////////////////////////////////
//%%+  +++++ End of ignored starting test - place for imports +++++

//%X+ xxxxx Start of the ovejumped text with declaration of the envelope xxxxx
/*******************************************************************************
 *<pre>
 * Předchozí:   No - this is a newly defined type
 *              Ttt in the project Ppp
 * Následující: No
 *
 * Project  Ppp
 *   + Adeed
 *   - Removed
 *   ~ Changed
 *</pre>
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
////////////////////////////////////////////////////////////////////////////////
//%X- ----- End of the ovejumped text with declaration of the envelope -----


/*******************************************************************************
 * Instances of class {@code Position} are trasport objects (crates)
 * containing dimensions.
 * Their attributes are therefore defined as public constants.
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
public class Area
{
//== CONSTANT CLASS ATTRIBUTES =================================================
//%X+ <999

    /** Field indicating that hash code was not yet computed. */
    private static final int INIT_HASH_CODE = Integer.MIN_VALUE;



//%X-
//== VARIABLE CLASS ATTRIBUTES==================================================
//== STATIC CONSTRUCTOR (CLASS INITIALIZER, STATIC INICITALIZING BLOCK) ========
//== CONSTANT INSTANCE ATTRIBUTES ==============================================

    /** Horizontal coordinate of the area = of its upper left corner. */
    public final int x;

    /** Vertical coordinate of the area = of its upper left corner. */
    public final int y;

    /** Object width. */
    public final int width;

    /** Object height. */
    public final int height;



//== VARIABLE INSTANCE ATTRIBUTES===============================================
//%X+ <999

    /** Hash-code is computed only once. */
    private int hashCode = INIT_HASH_CODE;



//%X-
//== CLASS GETTERS AND SETTERS =================================================
//== OTHER NON-PRIVATE CLASS METHODS ===========================================

//##############################################################################
//== CONSTUCTORS AND FACTORY METHODS============================================

    /***************************************************************************
     * Creates new area with given position and dimensions.
     *
     * @param x Horizontal coordinate of the upper left corner
     * @param y Vertical coordinate of the upper left corner
     * @param width  Width of the area
     * @param height Height of the area
     */
    public Area(int x, int y, int width, int height)
    {
        this.x     = x;
        this.y     = y;
        this.width = width;
        this.height = height;
    }


    /***************************************************************************
     * Creates new area with given position and dimensions.
     *
     * @param position Position of the upper left corner
     * @param size     Size of the area
     */
    public Area(Position position, Size size)
    {
        this(position.x, position.y, size.width, size.height);
    }



//== ABSTRACT METHODS ==========================================================
//== INSTANCE GETTERS AND SETTERS ==============================================

    /***************************************************************************
     * Returns the horizontal coordinate.
     *
     * @return  The horizontal coordinate
     */
    public int getX()
    {
        return x;
    }


    /***************************************************************************
     * Returns the vertical coordinate.
     *
     * @return  The vertical coordinate
     */
    public int getY()
    {
        return y;
    }


    /***************************************************************************
     * Returns the positon af the area.
     *
     * @return  The positon af the area
     */
    public Position getPosition()
    {
        return new Position (x, y);
    }


    /***************************************************************************
     * Returns the area's width.
     *
     * @return  Area's width
     */
    public int getWidth()
    {
        return width;
    }


    /***************************************************************************
     * Returns the area's height.
     *
     * @return  Area's height
     */
    public int getHeight()
    {
        return height;
    }


    /***************************************************************************
     * Returns the area's size.
     *
     * @return  Area's size
     */
    public Size getSize()
    {
        return new Size(width, height);
    }



//== OTHER NON-PRIVATE INSTANCE METHODS ========================================
//%A+ >127

    /***************************************************************************
     * Indicates whether object given in the pqarameter
     * is "equal to" this one.
     *
     * @param  object  The reference object with which to compare
     * @return {@code true} if this object hass the same attributes
     *         as the {@code object} argument; {@code false} otherwise
     */
    @Override
    public boolean equals(Object object)
    {
//%A-
//%I+ >127 -135
//        return (object instanceof Area)              &&
//               (((Area)object).x     == this.x)      &&
//               (((Area)object).y     == this.y)      &&
//               (((Area)object).width == this.width)  &&
//               (((Area)object).height == this.height);
//%I-
//%A+ >135
        if (! (object instanceof Area)) {
            return false;               //==========>
        }
        Area druhá = (Area)object;
        return (druhá.x     == x)     && (druhá.y     == y)    &&
               (druhá.width == width) && (druhá.height == height);
//%A-
//%A+ >127
    }

//%A-
//%X+ <999

    /***************************************************************************
     * Returns a hash code value for the object.
     *
     * @return  A hash code value for this object
     */
    @Override
    public int hashCode()
    {
        if (hashCode == INIT_HASH_CODE) {
            hashCode = (((17 + x) * 67 + y) * 67 + width) * 67 + height;
        }
        return hashCode;
    }

//%X-
//%X+ <126

    /***************************************************************************
     * Returns a string representation of the object.
     * It is used mostly for debugging purposes.
     *
     * @return String representation of the instance
     */
    @Override
    public String toString()
    {
        return "Area:[x=" + x + ", y=" + y +
               ", width=" + width + ", height=" + height + "]";
    }

//%X-
//%X+ <126


//%X-
//== PRIVATE AND AUXILIARY CLASS METHODS =======================================
//== PRIVATE AND AUXILIARY INSTANCE METHODS ====================================
//== EMBEDDED AND INNER CLASSES ================================================
//== TESTING CLASSES AND METHODS ===============================================
}
